const mysql = require('mysql');

// 创建连接对象
const con = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '456712Wn,',
  port: '3306',
  database: 'myblog'
});

// 开始连接
con.connect();

// 执行 sql 语句
const sql = `select username, realname from users where username='zhangsan' and password='123';`;
con.query(sql, (err, result) => {
  if(err) {
    console.error(err);
    return;
  } else {
    console.log(result);
    console.log(result[0])
  }
});

// 关闭连接
con.end();
